package cn.com.cnxfs.relaxchat.controller;

import cn.com.cnxfs.relaxchat.entity.Login;
import cn.com.cnxfs.relaxchat.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/login")
public class LoginController {
    @Autowired
    private ILoginService iLoginService;

    @RequestMapping(value="/login",method = RequestMethod.POST)
    private Login login(@RequestBody Login login){
        return iLoginService.login(login.getUsername(), login.getPassword());
    }

    @RequestMapping(value="/search",method = RequestMethod.POST)
    private Login search(@RequestParam String username){
        return iLoginService.search(username);
    }

    @RequestMapping(value="/getid",method = RequestMethod.POST)
    private Login getid(@RequestParam int id){
        return iLoginService.getid(id);
    }

    @RequestMapping(value="/add",method = RequestMethod.POST)
    private void add(@RequestBody Login login){
        iLoginService.add(login.getUsername(), login.getPassword(), login.getNickname());
    }

    @RequestMapping(value="/update_pass",method = RequestMethod.POST)
    private void update_pass(@RequestParam int id, @RequestParam String password){
        iLoginService.update_pass(id, password);
    }

    @RequestMapping(value="/update_name",method = RequestMethod.POST)
    private void update_name(@RequestParam int id, @RequestParam String nickname){
        iLoginService.update_name(id, nickname);
    }

    @RequestMapping(value="/del",method = RequestMethod.POST)
    private void del(@RequestParam int id){
        iLoginService.del(id);
    }
}
